* ======================================
* ---------- Network 2 step ------------
* ======================================



* Fam1Work1
* =========
* (candidate family -> worknet -> voter)

	* 2nd step: coworkers of self
	use "$dta\NetworkWork1.dta", clear
	keep idPers Work1net
	rename idPers idPers_tmp
	joinby Work1net using $dta\NetworkWork1.dta
	drop if idPers_tmp == idPers // drop self

	* 1st step: family of co-workers
	joinby idPers using $dta\NetworkFam1.dta
	rename idPers idMediator
	rename idPers_tmp idPers
	rename idFam1 idFam1Work1
	drop if idPers == idFam1 // drop self
	
	keep idPers idFam1Work1 idMediator
	sort idPers idFam1Work1
	save $dta/NetworkFam1Work1.dta, replace

	

* Work1Fam1
* =========
* (candidate worknet -> family -> voter)

	* 2nd step: family of self
	use "$dta\NetworkFam1.dta", clear
	keep idPers idFam1

	* 1st step: work networks of family
	rename idPers idPers_tmp
	rename idFam1 idPers
	joinby idPers using $dta\NetworkWork1.dta	
	rename idPers idMediator
	rename idPers_tmp idPers
	rename Work1net Work1Fam1net
	
	keep idPers Work1Fam1net idMediator
	sort idPers Work1Fam1net
	save $dta/NetworkWork1Fam1.dta, replace
	

	
* Fam1Imm1
* ========
* (candidate family -> immnet -> voter)

	* 2nd step: immigrant network of self
	use "$dta\NetworkImm1.dta", clear
	keep idPers Imm1net
	rename idPers idPers_tmp	
	joinby Imm1net using $dta\NetworkImm1.dta
	drop if idPers_tmp == idPers // drop self

	* 1st step: family of co-workers
	joinby idPers using $dta\NetworkFam1.dta
	rename idPers idMediator
	rename idPers_tmp idPers
	rename idFam1 idFam1Imm1
	drop if idPers == idFam1 // drop self
	
	keep idPers idFam1Imm1 idMediator
	sort idPers idFam1Imm1
	save $dta/NetworkFam1Imm1.dta, replace
	
	
	
* Imm1Fam1
* =========
* (candidate immnet -> family -> voter)

	* 2nd step: family of self
	use "$dta\NetworkFam1.dta", clear
	keep idPers idFam1

	* 1st step: imm networks of family
	rename idPers idPers_tmp
	rename idFam1 idPers
	joinby idPers using $dta\NetworkImm1.dta	
	rename idPers idMediator
	rename idPers_tmp idPers
	rename Imm1net Imm1Fam1net
	
	keep idPers Imm1Fam1net idMediator
	sort idPers Imm1Fam1net
	save $dta/NetworkImm1Fam1.dta, replace